package cm309.BookingSystem.web.model;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.beans.factory.annotation.Qualifier;

import cm309.BookingSystem.common.Common;

@Service("memberService")
public class MemberService {

	@Autowired
	@Qualifier("memberDAO")
    private MemberDAO memberDAO;
   
	public MemberDAO getMemberDAO() {
		return memberDAO;
	}

	public void setMemberDAO(MemberDAO memberDAO) {
		this.memberDAO = memberDAO;
	}

	public List<Member> getAll() {
		return memberDAO.getAll();
	}
	
	public Member loginMember(String loginName, String password) {
		Member mb=memberDAO.getMemberByMemberName(loginName);
		Common.logger.info("Input MemberName/password="+loginName+":"+password);
		if (mb!=null) {
			if(mb.password.equals(password)) {
				Common.logger.info(loginName+ " Login Success!" );
	         return mb;
			}else{
				Common.logger.info("MemberPassword wrong:"+mb.password+" vs "+password );
			    return null;
			}
		}else{
			Common.logger.info("MemberName isn't exisit");
		   return null;
		}   
	}
	
	public Member createMember(String memberName,String loginName,String pw,int memberAge,String email) {
		return memberDAO.createMember(memberName, loginName, pw, memberAge, email);
	}
}
